package com.example.springmavcase;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2023-10-27
 * Time:17:46
 * Text：
 */
@RestController
@RequestMapping("/user")
public class login {

    @RequestMapping("/login")
    public Boolean login(String username, String password, HttpSession session){
        System.out.println("“1234”");
        if(username.equals("zhangsan") && password.equals("1234"))
        {
            session.setAttribute("username","zhangsan");
            return true;
        }else{
            return false;
        }
    }
    @RequestMapping("/getUserInfo")
    public String getUserInfo(HttpServletRequest req){
        HttpSession  session=req.getSession(false);
        String username=null;
        if(session!=null){
            username=(String)session.getAttribute("username");
        }

        return username;
    }

}
